var StringUtil = function () {
    return {
        format: function (n, r) {
            return n.replace(/\{(\d+)\}/g, function (n, t) {
                return typeof r[t] != "undefined" ? r[t] : n;
            })
        },
        ashCode: function (n) {
            if (typeof n != "string") return "not string";
            var r = 0;
            if (n.length === 0) return r;
            for (i = 0; i < n.length; i++) {
                r = (r << 5) - r + n.charCodeAt(i);
                r = r & r;
            }
            return r;
        },
        //专业匹配中文  ,限制字符串长度
        beautySub: function (str, len) {
            var reg = /[\u4e00-\u9fa5]/g,
                slice = str.substring(0, len),
                chineseCharNum = (~~(slice.match(reg) && slice.match(reg).length)),
                realen = slice.length * 2 - chineseCharNum;
            return str.substr(0, realen) + (realen < str.length ? "..." : "");
        },
        //去所有空格
        trim: function (str) {
            return str.replace(/\s+/g, "");
            str = str.replace(/^\s+|\s+$/g, "");
            str = str.replace(/^\s*/, '');
            str = str.replace(/(\s*$)/g, "");
        },
        //是否为数字
        isNum: function (str) {
            if (isNaN(parseInt(str))) {
                return false;
            }
            return true;
        },
    }
}();